package com.gitee.fsadmin.controller.order;

import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.LambdaQuery;
import com.gitee.fsadmin.common.req.IdParam;
import com.gitee.fsadmin.common.resp.Result;
import com.gitee.fsadmin.common.util.CopyUtil;
import com.gitee.fsadmin.controller.order.param.OrderInfoAddParam;
import com.gitee.fsadmin.controller.order.param.OrderInfoSearchParam;
import com.gitee.fsadmin.controller.order.param.OrderInfoUpdateParam;
import com.gitee.fsadmin.controller.order.vo.OrderInfoVO;
import com.gitee.fsadmin.dao.entity.OrderInfo;
import com.gitee.fsadmin.service.order.OrderInfoService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.validation.annotation.Validated;


/**
 * @author thc
 */
@Controller
@Mapping("order")
public class OrderInfoController {

    @Inject
    private OrderInfoService orderInfoService;

    /**
     * 分页查询
     *
     * @param param 查询参数
     * @return 返回分页结果
     */
    @Get
    @Mapping("/page")
    public Result<PageInfo<OrderInfoVO>> page(OrderInfoSearchParam param) {
        LambdaQuery<OrderInfo> query = param.toLambdaQuery(OrderInfo.class);
        PageInfo<OrderInfoVO> pageInfo = orderInfoService.doPage(query)
          .convert(data -> CopyUtil.copyBean(data, OrderInfoVO::new));
        return Result.ok(pageInfo);
    }
    
    /**
     * 新增记录
     *
     * @param param 表单参数
     * @return 返回添加后的主键值
     */
    @Post
    @Mapping("/add")
    public Result<Long> add(@Validated OrderInfoAddParam param) {
        OrderInfo orderInfo = CopyUtil.copyBean(param, OrderInfo::new);
        orderInfoService.save(orderInfo);
        // 返回添加后的主键值
        return Result.ok(orderInfo.getId());
    }
    
    /**
     * 修改记录
     *
     * @param param 表单数据
     * @return 返回影响行数
     */
    @Post
    @Mapping("/update")
    public Result<Integer> update(@Validated OrderInfoUpdateParam param) {
        OrderInfo orderInfo = CopyUtil.copyBean(param, OrderInfo::new);
        return Result.ok(orderInfoService.update(orderInfo));
    }
					        
    /**
     * 删除记录
     *
     * @param param 参数
     * @return 返回影响行数
     */
    @Post
    @Mapping("/delete")
    public Result<Integer> delete(@Validated IdParam param) {
        return Result.ok(orderInfoService.deleteById(param.getId()));
    }
    
									
    
}